﻿CREATE PROCEDURE [dbo].[proc_Customer_SearchCusName]
	(
		@CusName nvarchar(50),
		@UserName nvarchar(50)
	)
AS
Begin
	DECLARE @CompanyId int,@cSql nvarchar(3000)
	Select @CompanyId=CompanyId From Employee Where UserName=@UserName

	Set @cSql = ';WITH List As(Select Top 5
		Id,CustomerId,'''' As Tel,
		IsNull(CustomerName,'''') CustomerName,
		IsNull(MnemonicWorks,'''') MnemonicWorks,
		Convert(varchar(2),ProtectId) As Protect,
		IsNull((Select Top 1 EName From Employee Where UserName=Customer.CreateName),'''') As CreateNameEName,
		IsNull(SourceId,0) SourceId,CreateDate
		From Customer
		Where CompanyId='+Convert(varchar(10),@CompanyId)+' And Audit=1
		--And	CustomerName Like ''%'+@CusName+'%''
			And	CustomerName='''+@CusName+'''
	)

	Select * From List Where CustomerName Not Like ''%-zd-%'''

	Exec(@cSql)
End
